<?php
class role extends base{

	public function init(){ // 公用
		parent::init(); // 这是必须的

		$this->tit = '角色';
		$this->modelObj = D('company_role');
		$this->accessObj = D('sys_access');

		$this->data_list = $this->modelObj->get_treeList("status=1 ".$this->cond_base);

	}

	//列表
	public function index(){
		$this->tabtit = array('全部','禁用');

		$cond = "1=1 ".$this->cond_base;

		//加入查询条件
		switch($this->tab){
			case '1':
				$cond .=" and status=0";
				break;
			default:
				$cond .=" and status=1";
		}
		//搜索
		if($this->keyword){
			$cond.=" and (name like '%".$this->keyword."%') ";
		}

		$this->list = $this->modelObj->get_treeList($cond);

	}




	// 授权
	public function auth(){

		$id = arg('id');
		if($this->isAjax()){
			$data = $this->postData('data');

			$arrBase['access_ids'] = joinStr($data['access']);

			$this->modelObj->edit($id,$arrBase);
			$this->renderSuccess('操作成功', "/{$this->routeUrl}/index");
		}
		$this->info = $this->modelObj->findById($id);

		$cond = "status=1 and type=3";
		$this->accessList = $this->accessObj->get_JsTree($cond,$this->info['access_ids'],'name');

	}

}